from django.db import models

# Create your models here.
class Users(models.Model):
    # 用户名 密码  手机号 邮箱 性别 年龄 头像  状态 注册时间
    username = models.CharField(max_length=50)
    password = models.CharField(max_length=77)
    phone = models.CharField(max_length=11)
    email = models.CharField(max_length=100,null=True)
    sex = models.CharField(max_length=1,choices=((0,'女'),(1,'男'),(2,'保密')),default='2')
    age = models.IntegerField(null=True)
    pic_url = models.CharField(max_length=100,null=True)
    # 0 正常  1禁用  2删除 3管理员
    status = models.IntegerField(default=0)
    addtime = models.DateTimeField(auto_now_add=True)

    class Meta:
        # 指定生成权限
        permissions = (
            ("show_users", "查看会员管理"),
            ("insert_users", "添加会员"),
            ("edit_users", "修改会员"),
            ("del_users", "删除会员"),
        )

# 商品分类模型
class Cates(models.Model):
    name = models.CharField(max_length=50)
    pid = models.IntegerField()
    path = models.CharField(max_length=20)
    isDelete =models.BooleanField(default=False)
      # id   name  pid   path
      # 1    服装   0     0,
      # 2    男装   1     0,1,
      # 3    西服   2     0,1,2,
      # 4    女装   1     0,1,
      # 5    裙子   4     0,1,4,
      # 6    超短裙  5     0,1,4,5,
    class Meta:
        # 指定生成权限
        permissions = (
            ("show_types", "查看商品分类管理"),
            ("insert_types", "添加商品分类"),
            ("edit_types", "修改商品分类"),
            ("del_types", "删除商品分类"),
        )


# 商品模型
class  Goods(models.Model):
    # id  title标题cateid所属分类(外键)price价格store数量info详情pic_url图片status状态addtime添加时间clicknum点击量ordernum购买数量
    title = models.CharField(max_length=255)
    cateid = models.ForeignKey(to='Cates')
    price = models.FloatField()
    store = models.IntegerField()
    info = models.TextField()
    pic_url = models.CharField(max_length=100)
    # 0 新发布 1 热卖 2 下架
    status = models.IntegerField(default=0)
    clicknum = models.IntegerField(default=0)
    ordernum = models.IntegerField(default=0)
    addtime = models.DateTimeField(auto_now_add=True)

    class Meta:
        # 指定生成权限
        permissions = (
            ("show_goods", "查看商品管理"),
            ("insert_goods", "添加商品"),
            ("edit_goods", "修改商品"),
            ("del_goods", "删除商品"),
        )


# 购物车
class Cart(models.Model):
    # id uid所属用户(外键) goodsid添加的商品(外键) num数量
    uid = models.ForeignKey(to="Users")
    goodsid = models.ForeignKey(to="Goods")
    num = models.IntegerField()

# 收货地址模型
class Address(models.Model):
    # shr收货人  shdh收货电话  info详细地址 isChecked是否选择 
    uid = models.ForeignKey(to="Users")
    shr = models.CharField(max_length=50)
    shdh = models.CharField(max_length=11)
    sheng = models.IntegerField()
    shi = models.IntegerField()
    xian = models.IntegerField()
    # zhen = models.IntegerField(null=True)
    info = models.CharField(max_length=100)
    isChecked = models.BooleanField(default=False)
    isDelete =models.BooleanField(default=False)

    class Meta:
        # 指定生成权限
        permissions = (
            ("show_address", "查看地址管理"),
            ("insert_address", "添加地址"),
            ("edit_address", "修改地址"),
            ("del_address", "删除地址"),
        )




#城市联动
class Citys(models.Model):

    name = models.CharField(max_length=255)
    level = models.IntegerField()
    upid = models.IntegerField()


# 订单
class Order(models.Model):
    #uid用户id shr收货人 shdh收货电话 shdz收货地址 buytype支付方式 wl物流 totalprice总价 addtime订单创建时间 buytime订单支付时间 status订单状态
    uid = models.ForeignKey(to="Users")
    shr = models.CharField(max_length=50)
    shdh = models.CharField(max_length=11)
    shdz = models.CharField(max_length=100)
    buytype = models.CharField(max_length=10)
    wl = models.CharField(max_length=10)
    totalprice = models.FloatField()
    addtime = models.DateTimeField(auto_now_add=True)
    buytime = models.DateTimeField(null=True)
    # 0 新订单  1 已支付  2,已发货  3,已收货
    status = models.IntegerField(default=0)

    class Meta:
        # 指定生成权限
        permissions = (
            ("show_order", "查看订单管理"),
            ("insert_order", "添加订单"),
            ("edit_order", "修改订单"),
            ("del_order", "删除订单"),
        )

# 订单详情
class OrderInfo(models.Model):
    # orderid订单id goodsid商品id num数量 price价格 pic_url图片 title标题
    orderid = models.ForeignKey(to="Order")
    goodsid = models.IntegerField()
    title = models.CharField(max_length=255)
    price = models.FloatField()
    pic_url = models.CharField(max_length=100)
    num = models.IntegerField()

